package co.th.bjc.md.online.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

public class DataBusinessServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static Logger _logger = Logger.getLogger(DataBusinessServlet.class);
       
    public DataBusinessServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		_logger.debug(getClass() + " : doGet");
		this.validatePermission(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		_logger.debug(getClass() + " : doPost");
		this.validatePermission(request, response);
	}
	
	private void validatePermission(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		_logger.debug(getClass());
		HttpSession sess = request.getSession();
		if(sess.getAttribute("userID") != null){
			_logger.info(getClass() + " : TRUE");
			getServletContext().getRequestDispatcher("/jsp/datamanage/data_business.jsp").forward(request, response);
		}else{
			_logger.info(getClass() + " : FALSE");
			response.sendRedirect("LoginServlet");
		}
	}

}
